<?php

class Filters_List {
  private $listFilters = array(
    'dumb' => array(
      'class' => 'Filters_LastPoint',
      'title' => 'Все записи',
    ),
    'like_string' => array(
      'class' => 'Filters_LikeString',
      'title' => 'Вхождение строки',
    ),
  );
  
  private $ctx;
  
  public function __construct( $ctx ) {
    $this->ctx = $ctx;
  }
  
  public function getFiltersList( $current = '' ) {
    $list = array();
    
    foreach ( $this->listFilters as $key=>$val ) {
      $list[] = array( 'oid'=>$key, 'title'=>$val['title'] );
      if ( $key == $current ) {
        $list[count($list)-1]['current'] = true;
      }
    }
    
    return $list;
  }
  
  public function getFilterTitle( $filterName ) {
    if ( isset($this->listFilters) && isset($this->listFilters[$filterName]) ) {
      return $this->listFilters[$filterName]['title'];
    } else {
      return '';
    }
  }
  
  public function getFilterObject( $filterName ) {
    if ( empty($filterName) || !isset($this->listFilters[$filterName]['class']) ) {
      return new Object();
    }
    
    $this->ctx->rh->useClass($this->listFilters[$filterName]['class']);
    
    $object = new $this->listFilters[$filterName]['class']( $this->ctx );
    
    if ( !($object instanceof $this->listFilters[$filterName]['class']) ) {
      $object = new Object();
    }
    
    return $object;
  }
}